#!user/bin/env python3
# -- coding: utf-8 --
import time
from selenium.webdriver.edge.service import Service
from selenium.webdriver.common.by import By
from selenium import webdriver

drive = webdriver.Edge(service=Service(r'C:\Users\Administrator\PycharmProjects\web_crawler\MicrosoftWebDriver.exe'))
drive.get('https://www.baidu.com/')
# drive.minimize_window()
# 一、点击与切换 switch_to.window是切换tab页  window_handles获取当前所有页面
drive.find_element(By.XPATH, '//*[@href="http://tieba.baidu.com/"]').click()
time.sleep(3)
pages = drive.window_handles
drive.switch_to.window(pages[0])
# drive.switch_to.window(drive.window_handles[0])
time.sleep(3)
# 二、新建与切换
drive.execute_script("window.open('https://www.163.com/')")  # 打开新页面
time.sleep(3)
drive.execute_script("window.open('https://www.jd.com/')")
time.sleep(3)
drive.execute_script("window.open('https://www.douban.com/')")
time.sleep(3)
drive.switch_to.window(drive.window_handles[0])
time.sleep(5)
drive.quit()
